package cn.appsys.controller.developer;

import cn.appsys.pojo.DevUser;
import cn.appsys.service.developer.DevUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/dev")
public class DevLoginController {

    @Autowired
    private DevUserService devUserService;

    @RequestMapping("/login")
    public String login(){
        return "devlogin";
    }

    @RequestMapping("/dologin")
    public String dologin(String devCode, HttpSession session, Model model){
        DevUser devUser = devUserService.getDevUser(devCode);
        if (null!=devUser){
            session.setAttribute("devUserSession",devUser);
            return "redirect:/dev/platform/main";
        }else {
            model.addAttribute("error","用户名或密码不正确");
            return "devlogin";
        }
    }

    @RequestMapping("/platform/main")
    public String main(HttpSession session){
        if (session.getAttribute("devUserSession")==null){
            return "redirect:/dev/login";
        }
        return "developer/main";
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.removeAttribute("devUserSession");
        return "devlogin";
    }

}
